<?php
if($_FILES['pic']['error'] != 0){
    //说明文件上传产生错误
    $a['error'] = 1;
    $a['errMsg'] = '上传文件出错1！';
    echo json_encode($a);
    exit;
}
$a['pic'] = $_FILES['pic'];
$fileName = $_FILES['pic']['name'];
$fileExt = explode(".",$fileName);
$ext = strtolower(end($fileExt));
$allowExt = array('jpg','jpeg','png','gif');
if(in_array($ext,$allowExt)){
    //说明扩展名合格
    $picName = time().rand(1000,9999).".".$ext;
    if(move_uploaded_file($_FILES['pic']['tmp_name'],"./tx/".$picName)){
        $a['error'] = 0;
        $a['fileName'] = $picName;
    }
    else{
        $a['error'] = 1;
        $a['info1'] = $_FILES['pic']['tmp'];
        $a['info2'] = "./tx/".$picName;
        $a['errMsg'] = '上传文件出错！';
    }
}
else{
    $a['error'] = 1;
    $a['errMsg'] = '头像只能是jpg\jpeg\gif\png\这4种类型！';
}
echo json_encode($a);